//AB31 活动安排
import java.util.;

注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       int n = in.nextInt();
       int[][] arr = new int[n][2];
       for (int i = 0; i  n; i++) {
           arr[i][0] = in.nextInt();
           arr[i][1] = in.nextInt();
       }
       Arrays.sort(arr, (o1, o2) - {
           return o1[0]  o2[0]  -1  1;
       });
       int l = 0;
       int r = 0;
       int count = 1;
       while (r  n) {
           if (arr[l][1]  arr[r][0]) {
               l = arr[l][1]  arr[r][1]  l  r;
           } else {
               count++;
               l = r;
           }
           r++;
       }

       System.out.println(count);
   }
}
